package com.bjc.core.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import com.bjc.core.bean.request.MenuReqVO;
import com.bjc.core.bean.response.MenuVO;
import com.bjc.core.service.IMenuService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 菜单控制器
 * 
 * @author 杨文
 * @date 2017年8月11日 下午5:23:15
 */
@RestController
@RequestMapping("api/cloud")
@Api(value = "menu-api", tags = { "菜单相关接口" })
public class MenuController {

	@Autowired
	private IMenuService menuService;

	@ApiOperation("查询菜单")
	// @RequiresPermissions("lookup:findPage")
	@GetMapping("menu/findList")
	public ResultVO getMenupPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			MenuReqVO menuReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<MenuVO> menuVOs = menuService.getList(menuReqVO);
		return ResultGenerator.getSuccess(new PageInfo<MenuVO>(menuVOs));
	}

	@ApiOperation("添加菜单")
	@PostMapping("menu/create")
	public ResultVO createMenu(@RequestBody MenuReqVO menuReqVO) {
		int count = menuService.insert(menuReqVO);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新菜单")
	@PutMapping("menu/update")
	public ResultVO updateMenu(@RequestBody MenuReqVO menuReqVO) {
		int count = menuService.update(menuReqVO);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("删除菜单")
	@DeleteMapping("menu/delete/{id}")
	public ResultVO deleteMenuById(@ApiParam(value = "菜单id", required = true) @PathVariable("id") Integer id) {
		int count = menuService.deleteById(id);
		return ResultGenerator.getDeleteSuccess(count);
	}
}
